package com.alogic.swagger.redoc;

import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.doc.XsArray;
import com.alogic.xscript.doc.XsObject;
import com.alogic.xscript.plugins.Segment;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;

/**
 * 扩展Tag
 *
 * @since 1.6.13.7 [20200812 duanyy] <br>
 */
public class SwaggerTag extends Segment {
    private String $name;
    private String $desc;
    private String $displayName;

    public SwaggerTag(String tag, Logiclet p) {
        super(tag, p);
    }

    @Override
    public void configure(Properties p){
        super.configure(p);

        $name = PropertiesConstants.getRaw(p,"name","");
        $desc = PropertiesConstants.getRaw(p,"description","");
        $displayName = PropertiesConstants.getRaw(p,"displayName","");
    }

    @Override
    protected void onExecute(XsObject root, XsObject current, LogicletContext ctx, ExecuteWatcher watcher) {
        XsArray newCurrent = current.getArrayChild("tags",true);
        XsObject newObj = newCurrent.newObject();
        newObj.addProperty("name",PropertiesConstants.transform(ctx,$name,""));
        newObj.addProperty("description",PropertiesConstants.transform(ctx,$desc,""));
        newObj.addProperty("x-displayName",PropertiesConstants.transform(ctx,$displayName,""));
        super.onExecute(root,newObj,ctx,watcher);
        newCurrent.add(newObj);
    }
}